package com.sesame.api;

import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.net.InetAddress;

@Data
@Slf4j
@Component
@ConfigurationProperties(prefix = "fms")
public class FMSConfig implements InitializingBean {

    private String filePath;
    private String mapping;


    @Resource
    private Environment env;

    @Override
    public void afterPropertiesSet() throws Exception {
        if (StringUtils.isEmpty(this.mapping)) {
            String ip = InetAddress.getLocalHost().getHostAddress();
            String port = env.getProperty("server.port");
            this.mapping = "http://" + ip + ":" + port;
        }
    }
}
